package org.nlp2rdf.navigator.util;

import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import org.apache.log4j.PropertyConfigurator;

public class LogHelper {

	private static String log4jConfigFile = "log4j.properties";

	@SuppressWarnings("unused")
	private static String log = initFile();

	/**
	 * there has to be a better way to do this
	 * I couldn't get the logging to work though
	 * @return
	 */
	@Deprecated
	public static String touch(){return "touched";}
	
	private static String initFile() {

		URL url = new LogHelper().getClass().getClassLoader().getResource(log4jConfigFile);
		PropertyConfigurator.configure(url);

		return "aaa";

	}

	public static Set<String> getJavaUtilLogNames(){
		Set<String> s = new HashSet<String>();
		for(Enumeration<String> i =  java.util.logging.LogManager.getLogManager().getLoggerNames();i.hasMoreElements();){
			s.add(i.nextElement());
		}
		return s;
	}
	
	public static void setLevelJavaUtilLogging(Level level){
		for(String logName : getJavaUtilLogNames()){
			
			Logger l = LogManager.getLogManager().getLogger(logName);
			System.out.println("name:|"+logName+"| "+l);
			System.out.println("before"+l.getLevel());
			l.setLevel(level);
			System.out.println("after"+l.getLevel());
		}
		
	}
	
	public static void printSystemProperties(){
		System.getProperties().list(System.out);
		
		
	}

}
